import Vue from 'vue'

/**
 * 分类管理页面的data
 * @author chenzheng
 * @since 2020-8-25
 */
export default class TData{

  classificationList= [];
  secondClassificationList=[];
  thirdClassificationList=[];
  sortData = {
    sortList:[],
    sortLevel:1,
    sortName:"" //排序父级分类名
  };

  clearAll(){
    Vue.prototype.$ySpliceAll(this.classificationList,this.secondClassificationList, this.thirdClassificationList);
    return this;
  }

  setLevel1List(items){
    Vue.prototype.$yPushAll(this.classificationList,items);
    return this;
  }

  setLevel2List(items){
    Vue.prototype.$yPushAll(this.secondClassificationList,items);
    return this;

  }

  setLevel3List(items){
    Vue.prototype.$yPushAll(this.thirdClassificationList,items);
    return this;
  }

  clearLevel1(){
    Vue.prototype.$ySpliceAll(this.classificationList);
    return this;
  }
  clearLevel2(){
    Vue.prototype.$ySpliceAll(this.secondClassificationList);
    return this;
  }
  clearLevel3(){
    Vue.prototype.$ySpliceAll(this.thirdClassificationList);
    return this;
  }

  setList(level,items){

    switch (level) {
      case 1:
        this.setLevel1List(items);
        break;
      case 2:
        this.setLevel2List(items);
        break;
      case 3:
        this.setLevel3List(items);
        break;

    }

  }

  changeSort(index1,index2){
    let preObj = this.sortData.sortList[index1];
    this.sortData.sortList.splice(index1,1);
    this.sortData.sortList.splice(index2,0,preObj);
    this.sortData.sortList.forEach(function(item,index){
      item.sequence = index + 1;
    })
  }


}
